<template>
  <div>
    <div id="main" style="width: 800px; height: 600px"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      echartsData: "",
    };
  },
  methods: {
    getData() {
      this.$axios.get("reports/type/1").then((res) => {
        console.log(res);
        this.echartsData = res.data.data;
        this.setEchart();
        //请求数据成功之后 把数据赋值给 图表的配置
      });
    },
    //从接口里请求图表数据
    setEchart() {
      var chartDom = document.getElementById("main");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "Stacked Area Chart",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: this.echartsData.legend,
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: this.echartsData.xAxis,
        yAxis: this.echartsData.yAxis,
        series: this.echartsData.series,
      };
      console.log(option);

      option && myChart.setOption(option);
    },
  },

  mounted() {
    this.getData();
  },
};
</script>

<style lang="scss" scoped></style>
